package firstStage.part5;

/**
 * @ClassName: [MethodDemo4]
 * @Description: 方法重载
 * @Author: [黄劲松]
 * @CreateDate: [2021-02-06]
 * @Version: [v1.0]
 */
/*
方法重载指同一个类中定义的多个方法之间的关系，满足下列条件的多个方法相互构成重载
   ●多个方法在同一个类中
   ●多个方法具有相同的方法名
   ●多个方法的参数不相同，类型不同或者数量不同
方法重载特点
   重载仅对应方法的定义，与方法的调用无关，调用方式参照标准格式
   重载仅针对同一个类中方法的名称与参数进行识别，与返回值无关，换句话说不能通过返回值来判定两个方法是否相互构成重载
*/
public class MethodDemo4 {
    public static void main(String[] args) {
        int result = sum(20, 12);
        System.out.println(result);
        double result2 = sum(23.1, 33.0);
        System.out.println(result2);
        int result3 = sum(12, 434, 222);
        System.out.println(result3);

        System.out.println(compare(10, 20));
        System.out.println(compare((byte) 10, (byte) 20));
        System.out.println(compare((short) 10, (short) 20));
        System.out.println(compare(10L, 20L));
    }

    public static int sum(int a, int b) {
        return a + b;
    }

    public static double sum(double a, double b) {
        return a + b;
    }

    public static int sum(int a, int b, int c) {
        return a + b + c;
    }

    public static boolean compare(int a, int b) {
        System.out.println("int");
        return a == b;
    }

    public static boolean compare(long a, long b) {
        System.out.println("long");
        return a == b;
    }

    public static boolean compare(short a, short b) {
        System.out.println("short");
        return a == b;
    }

    public static boolean compare(byte a, byte b) {
        System.out.println("byte");
        return a == b;
    }
}
